package 程序员代码面试指南.位运算;

public class 整数的二进制表达中有多少个1 {

    public static void main(String[] args) {
        System.out.println(howMany1InNum(3));
    }

    public static int howMany1InNum(int num) {
        int res = 0;
        while (num != 0) {
            num = num & (num - 1);
            res++;
        }
        return res;
    }
}
